
package com.huizhan.web.controller;
 
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Sort.*;
import io.swagger.annotations.*;
import java.util.*;

import com.huizhan.web.dao.*;
import com.huizhan.web.model.*;
import com.huizhan.web.view.*;

/**
 * 展品api
 */
 
@Api(tags = "ExhibitorProduct",description = "展品")
@RestController
public class ExhibitorProductController {
    
    @Autowired
    private ExhibitorProductDao dao;
   
    /**
     * 获取展品集合
     * @return api结果
     */
    @ApiOperation(value = "获取展品集合")
    @RequestMapping(value =  "/api/ExhibitorProduct/",method = {RequestMethod.GET})
    public ApiResult<List<ExhibitorProduct>> Get(){
         ApiResult<List<ExhibitorProduct>> result=new ApiResult<List<ExhibitorProduct>>();
        try 
        {
            List<ExhibitorProduct> res = dao.findAll();
            result.setData(res);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据ID获取展品信息
     * @param id 展品ID
     * @return api结果
     */
    @ApiOperation(value = "根据ID获取展品信息")
    @RequestMapping(value =  "/api/ExhibitorProduct/{id}",method = {RequestMethod.GET})
    public ApiResult<ExhibitorProduct> Get(@PathVariable Long id){
        ApiResult<ExhibitorProduct> result=new ApiResult<ExhibitorProduct>();
        try
        {
            ExhibitorProduct model= dao.getOne(id);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据展商ID获取产品集合
     * @param exhibitorId 展商ID
     * @return api结果
     */
    @ApiOperation(value = "根据展商ID获取产品集合")
    @RequestMapping(value =  "/api/ExhibitorProduct/Exhibitor/{exhibitorId}",method = {RequestMethod.GET})
    public ApiResult<List<ExhibitorProduct>> Project(@PathVariable Long exhibitorId){
        ApiResult<List<ExhibitorProduct>> result=new ApiResult<List<ExhibitorProduct>>();
        try
        {
            List<ExhibitorProduct> model= dao.findByExhibitorId(exhibitorId);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 修改展品信息
     * @param id 展品ID
     * @param model 展品信息
     * @return api结果
     */
    @ApiOperation(value = "修改展品信息")
    @RequestMapping(value =  "/api/ExhibitorProduct/{id}",method = {RequestMethod.PUT})
    public ApiResult<ExhibitorProduct> Edit(@PathVariable Long id,@RequestBody ExhibitorProduct model){
        ApiResult<ExhibitorProduct> result=new ApiResult<ExhibitorProduct>();
        try
        {
            model.setExhibitorProductId(id);
            model.setCreateDate(new Date());
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 添加展品信息
     * @param model 展品信息
     * @return api结果
     */
    @ApiOperation(value = "添加展品信息")
    @RequestMapping(value =  "/api/ExhibitorProduct/",method = {RequestMethod.POST})
    public ApiResult<ExhibitorProduct> Add(@RequestBody ExhibitorProduct model){
         ApiResult<ExhibitorProduct> result=new ApiResult<ExhibitorProduct>();
        try
        {
            model.setCreateDate(new Date());
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除展品信息
     * @param id 展品ID
     * @return api结果
     */
    @ApiOperation(value = "删除展品信息")
    @RequestMapping(value =  "/api/ExhibitorProduct/{id}",method = {RequestMethod.DELETE})
    public ApiResult<Object> Delete(@PathVariable  Long id){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteById(id);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 查询展品集合
     * @param model 账号信息
     * @return api结果
     */
    @ApiOperation(value = "查询展品集合")
    @RequestMapping(value =  "/api/ExhibitorProduct/Search",method = {RequestMethod.POST})
    public ApiResult<List<ExhibitorProduct>> Search(@RequestBody PageProduct model){
         ApiResult<List<ExhibitorProduct>> result=new ApiResult<List<ExhibitorProduct>>();
         
        try
        {    
            PageRequest pageable = PageRequest.of(model.getPageIndex(),model.getPageSize(),Direction.DESC,"Exhibitor_Product_Id") ;            
            Page<ExhibitorProduct> page = dao.findByWhere(model.getName(),model.getRemark(),model.getProjectId(),model.getExhibitorId(),pageable);
            result.setData(page.getContent());
            result.setTotal(page.getTotalElements());
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
}

